<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>时间应用</title>
    <style>
      div {
        width: 600px;
        height: 200px;
        font-size: 30px;
        color: orangered;
      }
    </style>
  </head>
  <body>
    <div id="time"></div>
    <script>
      //模拟日历
      //需求：每天打开这个页面都能定时显示年月日和星期几

      //1.创建一个当前日期的日期对象
      var date = new Date();
      //2.然后获取其中的年、月、日和星期
      var year = date.getFullYear();
      var month = date.getMonth();
      var hao = date.getDate();
      var week = date.getDay();
      //        console.log(year+" "+month+" "+hao+" "+week);
      //3.赋值给div
      var arr = [
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六",
      ];
      var div = document.getElementById("time");
      div.innerText =
        "今天是：" + year + "年" + (month + 1) + "月" + hao + "日 " + arr[week];
    </script>
  </body>
</html>
